home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT14.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  3.5 KB  |  104 lines

  1. /*
  2. ==============================================================================
  3.               WordUp Graphics Toolkit Version 5.0                     
  4.                  Demonstration Program 14                         
  5.                                           
  6.  Demonstrates string input,mouse cursor shape and speed, and                  
  7.  wflashcursor, cursor coordinates (xc,yc).
  8.                                           
  9.  *** PROJECT ***                                                             
  10.  This program requires the file WGT5_WC.LIB to be linked.                    
  11.                                           
  12.  *** DATA FILES ***                                                          
  13.  NONE                                                                        
  14.                                WATCOM C++ VERSION 
  15. ==============================================================================
  16. */
  17.  
  18. #include <wgt5.h>
  19.  
  20.  
  21. void main(void)
  22. {
  23.   color palette[256];
  24.   short i;
  25.   short px,py,pbut;
  26.   short oldmode;
  27.  
  28.   char *charlist=" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_.";
  29.     /* this is a list of all the possible characters you can enter
  30.        with wstring. If the character is not in the list, nothing will
  31.        happen and the cursor will remain in the same position. */
  32.  
  33.   char *yesno="YNyn";             /* used for yes/no answers only */
  34.  
  35.   char *string;                   /* A temporary string variable */
  36.  
  37.   printf ("WGT Example #14\n\n");
  38.   printf ("This program demonstrates a few of the WGT text commands.\n");
  39.   printf ("After answering each prompt, you will be able to move the mouse\n");
  40.   printf ("as if it was a text cursor. Press a key to end the demo at that point.\n");
  41.   printf ("\n\nPress any key to continue.\n");
  42.   getch ();
  43.  
  44.   if ( !vgadetected () )
  45.   {
  46.     printf("Error - VGA card required for any WGT program.\n");
  47.     exit (0);
  48.   }
  49.   oldmode = wgetmode ();
  50.   vga256 ();
  51.  
  52.   wcls (0);
  53.   wtextcolor (15);
  54.   wsetcolor (8);
  55.   wtextbackground (7);
  56.   wtexttransparent (TEXTFGBG);
  57.   /* Both FG and BG are turned on so text will erase itself. */
  58.  
  59.   /* wstring allows strings to be entered using special keys such as
  60.      the arrow keys, backspace, delete, insert, home and end, etc. */
  61.  
  62.   string = (char *)malloc (11);           /* remember to add one for
  63.                          the null character. This
  64.                          string is 10 chars long. */
  65.  
  66.   strcpy (string, " ");                   /* now make sure it is empty */
  67.  
  68.   curspeed = 2400;      /* type in a string, try using the special keys */
  69.  
  70.   wouttextxy (8, 0, NULL, "Type in a string: ");
  71.   wstring (152, 0, string, charlist, 10);
  72.  
  73.   free (string);                         /* now free the memory */
  74.  
  75.   string = (char *)malloc (2);
  76.   strcpy (string, " ");
  77.  
  78.   /* now try a yes or no answer, try letters other than {YNyn} */
  79.   wouttextxy (8, 32, NULL, "Do you want to quit? ");
  80.   wstring (176, 32, string, yesno, 1);
  81.   free (string);
  82.  
  83.   wsetcursor (0, 7);                      /* now do something interactive */
  84.   curspeed = 20;                          /* with the mouse */
  85.   minit ();
  86.   moff ();
  87.   do {
  88.     px = mouse.mx;
  89.     py = mouse.my;
  90.     pbut = mouse.but;
  91.     xc = (px >> 3) << 3;        /* divide by 8 and multiply by 8 */
  92.     yc = (py >> 3) << 3;        /* to make 8*8 squares */
  93.     wflashcursor ();            /* Notice that the cursor uses wsetcolor */
  94.     if (mouse.but != 0)
  95.     {
  96.       wsetcolor (rand () % 64);
  97.       wline (0, 0, xc, yc);     /* do something with graphics as well */
  98.     }
  99.   } while (!kbhit ());
  100.   mdeinit ();                   /* Deinitialize the mouse handler */
  101.  
  102.   wsetmode (oldmode);
  103. }
  104.